package org.custom.spring.boot.security.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.custom.spring.boot.entity.Result;
import org.custom.spring.boot.security.entity.SystemUser;
import org.custom.spring.boot.security.service.SystemResourceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统资源相关网络接口
 *
 * @author LiKun
 * @date 2021/11/8
 */
@RestController
@RequestMapping("/resource")
@Api(tags = "系统资源相关网络接口")
public class SystemResourceController {
    @Resource
    private SystemResourceService systemResourceService;

    @GetMapping
    @ApiOperation("获取当前登录用户数据")
    @PreAuthorize("hasAnyRole('USER')")
    public Result<SystemUser> getSystemUser() {
        return Result.success(systemResourceService.getCurrentUser());
    }

    @GetMapping("/activity/users")
    @PreAuthorize("hasAnyRole('ADMIN')")
    @ApiOperation("获取当前活跃的登录用户数据")
    public Result<List<SystemUser>> getActivityUsers() {
        return Result.success(systemResourceService.getActivityUsers());
    }
}
